package com.hy.demo.learn.开发支持类库.Optional类;

import java.util.Optional;

/**
 * <p>
 *  Optional  java1.8 之后出来对null的处理类
 * </p>
 *
 * @author cjl
 * @version 1.0
 * @since 2020-08-28 09:38
 */
public class OptionalDemo {

    public static void main(String[] args) {
        MessageUtil.userMessage(MessageUtil.getMessage().orElse(new IMessageImpl()));
    }
}

class MessageUtil {

    private MessageUtil() {
    }

    public static Optional<IMessage> getMessage() {
        return Optional.ofNullable(null);
    }

    public static void userMessage(IMessage ms) {
        if (ms != null) {
            System.out.println(ms.getContent());
        }
    }
}

interface IMessage {

    public String getContent();
}

class IMessageImpl implements IMessage {
    @Override
    public String getContent() {
        return "旋转跳跃，旋转跳跃！";
    }
}
